﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using LogManager.Base.Data;

namespace LogManager.Config.Data
{
    public class ConfigLogTypeService : ILogTypeService
    {
        private readonly IEnumerable<LogTypeConfiguration> _logTypes;

        public ConfigLogTypeService(LogTypeCollection logTypeCollection)
        {
            _logTypes = logTypeCollection.Cast<LogTypeConfiguration>();
        }

        public IDictionary<string, Type> All()
        {
            return _logTypes.ToDictionary(t => t.TypeId, t => t.Type);
        }

        public Type Get(string typeId)
        {
            return _logTypes.Where(t => t.TypeId == typeId).Select(t => t.Type).SingleOrDefault();
        }

        public string Get(Type type)
        {
            return _logTypes.Where(t => t.Type == type).Select(t => t.TypeId).SingleOrDefault();
        }
    }
}
